//=============================================================================
//Name		:isr.c
//Purpose	:Interrupt Service Routine
//=============================================================================
#define		_ISR_C
#include    "includeAll.h"
//=============================================================================
// Function:	void INT0_int(void)
// Purpose:	INT0 pin interrupt vector
// Input:	none
// OutPut:	none
// Author:
//=============================================================================
void INT0_int(void) interrupt 0
{
	IE0 = 0;			//clear interrupt flag
}
//=============================================================================
// Function:	void TIMER0_int(void)
// Purpose:	TIMER0 interrupt vector
// Input:	none
// OutPut:	none
// Author:
//=============================================================================
void TIMER0_int(void) interrupt 1
{
	TF0 = 0;			//clear interrupt flag
	TR0 = 0;

	TH0 = (65536-7372)/256;	//4ms timer0 interrupt
	TL0 = (65536-7372)%256;
	TR0 = 1;
	
//DisplayScan();

	 KeyJudge();
   
     if(buzzConvertAdTimer > 0)
    {
        buzzConvertAdTimer-- ;
    }
    else{
        bBuzz = 0 ;
    }
	 if(buzzLastTimer > 0)
        {
            buzzLastTimer-- ;
        }
        else
        {
          	P3MODL  &=b0011_1111;
			P3MODL  |=b0100_0000;
            F_setBuzz()	;
        }
				
		timer40ms++;
    timer500ms++;
    timer1s++;	
}

void TIMER1_int(void) interrupt 3
{
	TF1 = 0;			//clear interrupt flag
	 TR1 = 0;
	 TR1 = 1;
  TH1 = (65536-276)/256;		//20ms timer1 interrupt
	TL1 = (65536-276)%256;
  DisplayScan();
  
}

void TIMER2_int(void) interrupt 5
{
	TF2 = 0;			//clear interrupt flag
	 if(buzzLastTimer > 0)
  {
      bBuzz = 1 ;   //标志位 蜂鸣
        F_buzz() ;
    }
	//P3_2=~P3_2;
	// clockAddTime++;
    // if(clockAddTime>=2)
   // {
      // clockAddTime=0;
  // DisplayScan();
   // }

	

P3MODH &=  b1111_1100;
P3MODH |=  b0000_0010;	
  bZero = D_crossZero ;
	//fireType=D_fireType_16_16;
	//bWattSetted=1;
	//fireType=8;
	
	if((bWattSetted)&&(bAdGood)){		
		if(bLastZero != bZero){
		//0->1 or 1-->0
			if(holdWatt >0){
				holdWatt--;
				if(holdFireType>0)
				{
						holdFireType--;
						F_triacOn() ;
						triacTimer = D_triacHoldTime ;	
					
					
				}
				
				
				
			}
			if(holdWatt==0)
			{
				holdWatt=D_watt;
				holdFireType=fireType;	
				
			}
			
		}		
	}
	if(triacTimer > 0){
		triacTimer--  ;	
	}
	
	else{
		F_triacOff() ;
	}
	
//	F_triacOn() ;
}
